export function basicType() {
  // 布尔值
  let isDone: boolean = false;
  // console.log(isDone);

  // 数字
  let decLiteral: number = 6;
  let hexLiteral: number = 0xf00d;
  let binaryLiteral: number = 0b1010;
  let octalLiteral: number = 0o744;
  // console.log("十进制:", decLiteral);
  // console.log("十六进制:", hexLiteral);
  // console.log("二进制:", binaryLiteral);
  // console.log("八进制:", octalLiteral);

  // 字符串
  let name: string = "bob";
  name = "smith";
  // console.log(name);
  let age: number = 37;
  let sentence: string = `Hello, my name is ${name}. I'll be ${
    age + 1
  } years old next month.`;
  // console.log(sentence);

  // 数组
  let list: number[] = [1, 2, 3];
  let list2: Array<number> = [1, 2, 3];
  // console.log(list, list2);

  // 元组 Tuple
  let x: [string, number];
  x = ["hello", 10]; // OK
  // x = [10, "hello"]; // Error
  // console.log(x);
  // console.log(x[0].slice(1)); // OK
  // // console.log(x[1].slice(1)); // Error, 'number' does not have 'slice'
  // console.log(x[1].toFixed(2)); // OK

  // 枚举
  // enum Color {
  //   Red,
  //   Green,
  //   Blue,
  // }
  // let c: Color = Color.Green;
  // console.log(c); // 1
  // console.log(Color[1]); // Green
  enum Color {
    Red = 1,
    Green,
    Blue,
  }
  let c: Color = Color.Green;
  // console.log(c); // 2
  let colorName: string = Color[2];
  // console.log(colorName);

  // Any
  let notSure: any = 4;
  notSure = "maybe a string instead";
  notSure = false; // okay, definitely a boolean
  // console.log(notSure);
  // notSure.ifItExists();
  // notSure.toFixed();
  let list3: any[] = [1, true, "free"];
  list3[1] = 100;
  // console.log(list3);

  // Void
  function warnUser(): void {
    console.log("This is my warning message");
    // return undefined;
  }
  // console.log(warnUser());
  let unusable: void = undefined;
  // console.log(unusable);

  // Null 和 Undefined
  let u: undefined = undefined;
  let n: null = null;
  // console.log(u, n);

  // Never
  // 返回never的函数必须存在无法达到的终点
  function error(message: string): never {
    throw new Error(message);
  }
  // 推断的返回值类型为never
  function fail() {
    return error("Something failed");
  }
  // fail();
  // 返回never的函数必须存在无法达到的终点
  function infiniteLoop(): never {
    while (true) {}
  }

  // Object
  let obj: Object = { x: 0 };
  // console.log(obj);
  let someValue: any = "this is a string";

  // 类型断言
  let strLength: number = (someValue as string).length;
  // let strLength1: number = (<string>someValue).length;
  // console.log(strLength, strLength1);
}
